feat: add gemini-nano-dev skill for Chrome built-in AI - #43
Conversation
Add a comprehensive skill for building web applications and Chrome Extensions using Chrome's built-in AI powered by Gemini Nano. The skill covers: - Prompt API (LanguageModel) for text generation - Multimodal input (image and audio understanding) - Structured output with JSON Schema constraints - Session management (context window, cloning, destroying) - Specialized APIs: Summarizer, Writer, Rewriter, Proofreader, Language Detector, and Translator - Chrome Extensions integration - Hardware requirements and localhost setup - Best practices for on-device AI development Also updates README.md to include the new skill in the skills table. Fixes google-gemini#17
There was a problem hiding this comment.
Code Review
This pull request introduces the gemini-nano-dev skill, providing comprehensive documentation and code examples for building web applications and Chrome Extensions using Chrome's built-in AI (Gemini Nano). The documentation covers the Prompt API, multimodal inputs, structured outputs, and specialized APIs like Summarizer and Translator. Feedback focuses on correcting API access patterns by using the ai namespace, fixing environment-specific code (replacing Node.js APIs with browser-compatible ones), and ensuring correct property and method names for session management and capabilities.
| Always check if the model is ready before creating a session: | ||
|
|
||
| ```javascript | ||
| const availability = await LanguageModel.availability({ |
There was a problem hiding this comment.
The Chrome built-in AI APIs are accessed via the window.ai namespace (e.g., ai.languageModel, ai.summarizer). Using the capitalized interface names like LanguageModel as global entry points is incorrect and will result in a ReferenceError. This pattern should be updated throughout the document for all APIs (Summarizer, Writer, etc.).
| const availability = await LanguageModel.availability({ | |
| const availability = await ai.languageModel.availability({ |
References
- Code examples in skill documentation should be minimal, demonstrating only the core SDK functionality. Avoid adding boilerplate like error handling, as the goal is to showcase SDK usage, not teach general coding practices.
| ### Summarizer API | ||
|
|
||
| ```javascript | ||
| const summarizer = await Summarizer.create(); |
There was a problem hiding this comment.
Specialized APIs should also be accessed via the ai namespace (e.g., ai.summarizer.create()) rather than using the interface name as a global.
| const summarizer = await Summarizer.create(); | |
| const summarizer = await ai.summarizer.create(); |
References
- Code examples in skill documentation should be minimal, demonstrating only the core SDK functionality. Avoid adding boilerplate like error handling, as the goal is to showcase SDK usage, not teach general coding practices.
| ```javascript | ||
| const stream = session.promptStreaming('Write a poem about the ocean.'); | ||
| for await (const chunk of stream) { | ||
| process.stdout.write(chunk); |
There was a problem hiding this comment.
process.stdout.write is a Node.js-specific API and is not available in the browser or Chrome Extension environments where these APIs are used. Use console.log or a DOM-based output method instead.
| process.stdout.write(chunk); | |
| console.log(chunk); |
References
- Code examples in skill documentation should be minimal, demonstrating only the core SDK functionality. Avoid adding boilerplate like error handling, as the goal is to showcase SDK usage, not teach general coding practices.
There was a problem hiding this comment.
+1, this should just be console.log(chunk);.
| ### Context Window Tracking | ||
|
|
||
| ```javascript | ||
| console.log(`Context usage: ${session.contextUsage}/${session.contextWindow}`); |
There was a problem hiding this comment.
The LanguageModel session object uses tokensSoFar and maxTokens to track context usage, rather than contextUsage and contextWindow.
| console.log(`Context usage: ${session.contextUsage}/${session.contextWindow}`); | |
| console.log("Context usage: " + session.tokensSoFar + "/" + session.maxTokens); |
References
- Code examples in skill documentation should be minimal, demonstrating only the core SDK functionality. Avoid adding boilerplate like error handling, as the goal is to showcase SDK usage, not teach general coding practices.
| All built-in AI APIs work in Chrome Extensions. For extensions using the Prompt API, you can customize model parameters: | ||
|
|
||
| ```javascript | ||
| const params = await LanguageModel.params(); |
There was a problem hiding this comment.
The method to retrieve model parameters and limits is capabilities(), not params(). Additionally, it should be called on the ai.languageModel factory.
| const params = await LanguageModel.params(); | |
| const params = await ai.languageModel.capabilities(); |
References
- Code examples in skill documentation should be minimal, demonstrating only the core SDK functionality. Avoid adding boilerplate like error handling, as the goal is to showcase SDK usage, not teach general coding practices.
tomayac
left a comment
There was a problem hiding this comment.
A solid start, however, here's significant overlap with:
- https://github.com/GoogleChromeLabs/web-ai-demos/tree/main/built-in-ai-skills-md-agent-md
- https://github.com/webmaxru/Agent-Skills
The task API skills are not detailed enough.
| Always check if the model is ready before creating a session: | ||
|
|
||
| ```javascript | ||
| const availability = await LanguageModel.availability({ |
| ```javascript | ||
| const stream = session.promptStreaming('Write a poem about the ocean.'); | ||
| for await (const chunk of stream) { | ||
| process.stdout.write(chunk); |
There was a problem hiding this comment.
+1, this should just be console.log(chunk);.
| ### Context Window Tracking | ||
|
|
||
| ```javascript | ||
| console.log(`Context usage: ${session.contextUsage}/${session.contextWindow}`); |
| ### Summarizer API | ||
|
|
||
| ```javascript | ||
| const summarizer = await Summarizer.create(); |
| All built-in AI APIs work in Chrome Extensions. For extensions using the Prompt API, you can customize model parameters: | ||
|
|
||
| ```javascript | ||
| const params = await LanguageModel.params(); |
| ## Enable on Localhost | ||
|
|
||
| 1. Go to `chrome://flags/#optimization-guide-on-device-model` → **Enabled** | ||
| 2. Go to `chrome://flags/#prompt-api-for-gemini-nano` → **Enabled** or **Enabled multilingual** | ||
| 3. For multimodal input: `chrome://flags/#prompt-api-for-gemini-nano-multimodal-input` → **Enabled** | ||
| 4. Restart Chrome | ||
| 5. Verify: Open DevTools console, run `await LanguageModel.availability()` |
There was a problem hiding this comment.
Obsolete now that the API ships in Chrome 148.
|
|
||
| ## Best Practices | ||
|
|
||
| 1. **Always check availability** before creating a session — the model may not be downloaded yet |
There was a problem hiding this comment.
Yes, and with the exact same options you'll pass to create().
Description
Add a comprehensive skill for building web applications and Chrome Extensions using Chrome's built-in AI powered by Gemini Nano (on-device model).
Fixes #17
Changes
New:
skills/gemini-nano-dev/SKILL.mdA complete skill covering all Chrome built-in AI APIs:
LanguageModel) — General-purpose text generation with system prompts, conversation history, and response prefixesresponseConstrainttopK,temperature)Modified:
README.mdAdded
gemini-nano-devto the skills table.Testing
gemini-api-dev,gemini-live-api-dev,gemini-interactions-api)nameanddescriptionfieldsRelated